package Box2D.Common.Math
{
	import Box2D.Common.b2Wrapper;

	public class b2Vec2 extends b2Wrapper
	{
		public function b2Vec2(x:Number=0,y:Number=0,wrapper:Object=null)
		{
			super(wrapper)
			if(wrapper==null)
				_wrapper = callDirect('b2Vec2_new',x,y);
		}
		public function get x():Number{return getNumber(0)}
		public function set x(value:Number):void{setNumber(0,value)}
		
		public function get y():Number{return getNumber(4)}
		public function set y(value:Number):void{setNumber(4,value)}
		
		public function SetZero():void{
			call('b2Vec2_SetZero');
		}
		public function Set(x:Number,y:Number):void{
			call('b2Vec2_Set',x,y);
		}
		public function Length():Number{
			return call('b2Vec2_Length');
		}
		public function LengthSquared():Number{
			return call('b2Vec2_LengthSquared');
		}
		public function Normalize():Number{
			return call('b2Vec2_Normalize');
		}
		public function IsValid():Boolean{
			return call('b2Vec2_IsValid');
		}
		public function Add(v:b2Vec2) : b2Vec2
		{
		 	return new b2Vec2(x + v.x,y + v.y);
		}
		public function AddWith(v:b2Vec2):void{
			x+=v.x;
			y+=v.y;
		}
		public function Subtract(v:b2Vec2) :b2Vec2
		{
			return new b2Vec2(x - v.x,y - v.y)
		}
		public function SubtractWith(v:b2Vec2):void{
			x-=v.x;
			y-=v.y;
		}
		
		public function Multiply(a:Number) : b2Vec2
		{
			return new b2Vec2(x * a, y * a)
		}
		
		public function MultiplyWith(a:Number):void
		{
			x*=a;
			y*=a;
		}
		
		public function Copy(source:b2Vec2):void{
			x = source.x;
			y = source.y;
		}
		public function toString():String{
			return '[' + x + ',' + y + ']';
		}
		public static function getArray(ptr:Object,count:int):Array{
			var result:Array = [];
			for(var i:int=0;i<count;i++){
				result.push(new b2Vec2(0,0,ptr+i*8))
			}
			return result;
		}
		public static function getVector(ptr:Object,count:int):Vector.<b2Vec2>{
			var result:Vector.<b2Vec2> = new Vector.<b2Vec2>(count);
			for(var i:int=0;i<count;i++){
				result[i] = new b2Vec2(0,0,ptr+i*8);
			}
			return result;
		}
	}
}